import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/modules/application/education/personal_profile/personal_profile_controller.dart';

class EducationProfileNameController extends GetxController {
  final profile = Get.find<EducationProfileController>();

  /// 是否正在修改实名认证
  final isEditing = false.obs;

  final nameCtrl = TextEditingController();
  final idCtrl = TextEditingController();

  /// 身份证正面
  String? get idPicFront => idPicFrontList.firstOrNull;
  List<String> idPicFrontList = [];

  /// 身份证背面
  String? get idPicBack => idPicBackList.firstOrNull;
  List<String> idPicBackList = [];

  void onProfileChanged() {
    nameCtrl.text = profile.entity?.nickname ?? '';
    idCtrl.text = profile.entity?.idNo ?? '';
    final idFront = profile.entity?.frontOfIdCardUrl;
    if (idFront != null && idFront.isNotEmpty) idPicFrontList = [idFront];
    final idBack = profile.entity?.reverseOfIdCard;
    if (idBack != null && idBack.isNotEmpty) idPicBackList = [idBack];
    update();
  }

  void onSaveChanges() {
    profile.entity?.nickname = nameCtrl.text;
    profile.entity?.idNo = idCtrl.text;
    if (idPicFront != null) profile.entity?.frontOfIdCardUrl = idPicFront!;
    if (idPicBack != null) profile.entity?.reverseOfIdCard = idPicBack!;
  }
}
